package com.usefullc.user.dao;

import com.usefullc.user.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 用户DAO
 * @author: Sampson
 * @date: 2018-12-19 16:06
 */
public interface UserDao extends JpaRepository<User, Long> {

    @Transactional
    @Modifying
    @Query(value = "update `u_user` t set t.status = ?2,t.gmtModified=now(6) where t.id = ?1 and t.status != ?2",nativeQuery = true)
    int updateStatus(Long id,Integer status);

    @Transactional
    @Modifying
    @Query(value = "update `u_user` t set t.status = ?2,t.gmtModified=now(6) where t.id in (?1) and t.status != ?2",nativeQuery = true)
    int updateAllStatus(List<Long> ids, Integer status);

    @Transactional
    @Modifying
    @Query(value = "update `u_user` t set t.pwd = ?2,t.gmtModified=now(6) where t.id in (?1) ",nativeQuery = true)
    int updateAllPwd(List<Long> ids, String pwd);


}
